package com.sogoodsoft.dao.crm;

import java.util.List;

import org.springframework.stereotype.Component;

import com.sogoodsoft.dao.common.CommonHibernateDao;
import com.sogoodsoft.entity.crm.DocFile;

@Component
public class DocFileDao extends CommonHibernateDao < DocFile, Long > {

    /**
     * 通过文档的ID，删除相关的附件
     * @param docId
     */
    public void deleteByDocId(Long docId){
        List<DocFile> list = this.getDocFiles(docId);
        if(list != null && list.size() > 0){
            for(DocFile d : list){
                this.delete(d.getId());
            }
        }
    }
    
    /**
     * 通过文档的docId,得到相关的附件列表
     * @param docId
     * @return
     */
    public List<DocFile> getDocFiles(Long docId){
        StringBuffer sb = new StringBuffer();
        sb.append("from DocFile where docid ="+docId);
        List<DocFile> list = this.find(sb.toString());
        return list;
    }
}
